﻿using System;
using System.Web;

namespace BG.Web
{
    /// <summary>
    /// LoginHandler 的摘要说明
    /// </summary>
    public class LoginHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                string loginUrl = string.Empty;
                string returnUrl = context.Request.Params["returnUrl"].ToLower();
                if (returnUrl.Contains("admin"))
                {
                    loginUrl = "/ExtLogin.aspx";
                }
                else if (returnUrl.Contains("company"))
                {
                    loginUrl = "/CompanyLogin.aspx";
                }
                else
                {
                    loginUrl = "/Login.aspx";
                }
                if (!string.IsNullOrEmpty(context.Request.Params["returnUrl"]))
                {
                    loginUrl = loginUrl + "?returnUrl=" + HttpUtility.UrlEncode(context.Request.Params["returnUrl"]);
                }
                context.Response.Redirect(loginUrl, true);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}